package com.yiwei.zxp.util;

import android.text.TextUtils;

import com.yiwei.zxp.activity.GoodsAddActivity;
import com.yiwei.zxp.api.bean.GoodsAddBean;
import com.yiwei.zxp.api.bean.ParamsBean;
import com.yiwei.zxp.api.model.GoodsDetailModel;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by xsooy-pc on 18-5-24.
 */

public class GoodsOperator {
    private GoodsAddBean submitData;
    private GoodsAddActivity context;
//    private ArrayList<String> details;

    public GoodsOperator(GoodsAddActivity activity) {
        this.context = activity;
        submitData = new GoodsAddBean();
        submitData.photos = new ArrayList<>();
//        for (int i = 0; i < 3; i++) {
//            submitData.photos.add("");
//        }
    }

    public void initData(GoodsDetailModel.DatasBean item) {
        submitData.goods_no = item.goods_no;
        submitData.cate_id = item.cate_id;
        submitData.city_id = item.city_id;
        submitData.deliver_fee = item.deliver_fee;
        submitData.details = item.details;
        submitData.params = item.params;
        submitData.photos = item.photos;
        submitData.price = item.price;
        submitData.title = item.title;
        submitData.inventory = item.inventory;
        submitData.province_id = item.province_id;
    }


    public GoodsAddBean getSubmitData() {
        return submitData;
    }

    public void setDeliverFee(String deliver_fee) {
        submitData.deliver_fee = deliver_fee;
    }


    public void setPhotosIndex(int index, String item) {
        if (submitData.photos.size() < index + 1) {
            submitData.photos.add(item);
        } else {
            submitData.photos.set(index, item);
        }
    }

    public void setCateId(String cate_id) {
        submitData.cate_id = cate_id;
    }

    public void setAddress(String province_id, String city_id) {
        submitData.province_id = province_id;
        submitData.city_id = city_id;
    }

    public ArrayList<String> getDetails() {
        return submitData.details;
    }

    public void setTitle(String title) {
        submitData.title = title;
    }

    public void setPrice(String price) {
        submitData.price = price;
    }

    public void setGoodsNum(String num) {
        submitData.inventory = num;
    }

    public void setParams(List<ParamsBean> params) {
        submitData.params = params;
    }

    public List<ParamsBean> getParams() {
        return submitData.params;
    }

    public void setPhotos(List<String> photos) {
        submitData.photos = photos;
    }

    public List<String> getPhotos() {
        return submitData.photos;
    }

    public void setDetails(ArrayList<String> details) {
        submitData.details = details;
    }

    public boolean checkInput() {
        if (TextUtils.isEmpty(submitData.title)) {
            ToastUtil.makeText(context, "标题不能为空");
            return false;
        }
        if (TextUtils.isEmpty(submitData.price)) {
            ToastUtil.makeText(context, "价格不能为空");
            return false;
        }
        if (TextUtils.isEmpty(submitData.deliver_fee)) {
            ToastUtil.makeText(context, "快递服务不能为空");
            return false;
        }
        if (TextUtils.isEmpty(submitData.province_id)) {
            ToastUtil.makeText(context, "商品发货地不能为空");
            return false;
        }
        if (TextUtils.isEmpty(submitData.inventory)) {
            ToastUtil.makeText(context, "库存不能为空");
            return false;
        }
        if (TextUtils.isEmpty(submitData.cate_id)) {
            ToastUtil.makeText(context, "分类不能为空");
            return false;
        }
        if (submitData.params == null || submitData.params.size() == 0) {
            ToastUtil.makeText(context, "参数不能为空");
            return false;
        }
        if (submitData.photos == null || submitData.photos.size() == 0) {
            ToastUtil.makeText(context, "展示图片不能为空");
            return false;
        }
        if (submitData.details == null || submitData.details.size() == 0) {
            ToastUtil.makeText(context, "商品详情不能为空");
            return false;
        }
        return true;
    }
}
